<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>

	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">

	<title>用户管理·思通投研·让数据驱动投资价值!</title>
	<link href="${pageContext.request.contextPath }/img/webLogoIcon.png" rel="shortcut icon">
	<link href="${pageContext.request.contextPath }/css/bootstrap.min.css" rel="stylesheet">
	<link href="${pageContext.request.contextPath }/css/font-awesome.css" rel="stylesheet">
	<link href="${pageContext.request.contextPath }/css/mypage.css" rel="stylesheet">
	<link href="${pageContext.request.contextPath }/css/animate.css" rel="stylesheet">
	<link href="${pageContext.request.contextPath }/css/style.css" rel="stylesheet">
	<!-- Toastr style -->
	<link href="${pageContext.request.contextPath }/css/plugins/toastr/toastr.min.css" rel="stylesheet">
</head>

<body>
<div id="wrapper">
	<nav class="navbar-default navbar-static-side" role="navigation">
        <%request.setAttribute("LEFT", "user");%>
		<%@include file="left.jsp"%>
    </nav>
    <div id="page-wrapper" class="gray-bg">
	    <div class="row border-bottom">
	     	<jsp:include page="head.jsp" flush="true" /> 
	    </div>
	    <div class="row wrapper border-bottom white-bg page-heading">
	        <div class="col-lg-9">
	            <h2>用户管理</h2>
	            <ol class="breadcrumb">
	                	<li class="nav-main1">
	                		<a href="${pageContext.request.contextPath}/admin/tosystem_overview">主页</a>
	                	</li>
	                	<li class="nav-main2" >
	                		<a id="navigation1" href="#" >系统设置</a>
	                	</li>
	                	<li class="nav-main3" style="display: none">
	                		<a id="navigation2"></a>
	                	</li>
	                	<li class="active">
	                		<a>用户管理</a>
	                	</li>
                	</ol>
	        </div>
	        <div class="col-lg-3">
	        	<div class="pull-left" style=" margin-top: 18%;"><strong>当前共:${list.total }名用户</strong></div> 
	        </div>  
	    </div>
		<div class="wrapper wrapper-content  animated fadeInRight" style="width: 100%;">
			<div class="row" style="width: 100%;">
				<div class="col-sm-8" style="width: 100%;">
					<div class="ibox">
						<div class="ibox-content">
							<div class="text-center">
								<a href="${pageContext.request.contextPath }/register" class="text-muted small pull-right" >+创建新用户</a>
							</div>
							<!-- <h2>用户管理</h2> -->
							<!-- <div class="input-group">
								<input type="text" placeholder="搜索客户 " class="input form-control">
								<span class="input-group-btn">
									<button type="button" class="btn btn btn-primary">
										<i class="fa fa-search"></i> 开始搜索
									</button>
								</span>
							</div> -->
							<div class="clients-list">
								<ul class="nav nav-tabs">
									<span id="persons" class="pull-right small text-muted"></span>
									<li class="active"><a data-toggle="tab" href="#tab-1"><i
											class="fa fa-user"></i> 账号管理</a></li>
								</ul>
								<div class="tab-content">
									<div id="tab-1" class="tab-pane active" style="height: auto;">
										<!-- <div class="full-height-scroll"> -->
											<div class="table-responsive">
												<table class="table table-hover">
													<thead>
														<tr>
															<td class="client-avatar"></td>
															<td><a data-toggle="tab" href="#contact-1" class="client-link">用户名</a></td>
															<td>姓名</td>
															<td>角色</td>
															<td>状态</td>
															<td class="contact-type"></td>
															<td>创建日期</td>
															<td class="client-status">操作</td>
														</tr>
													</thead>
													<tbody id="userAll" >
														<c:forEach items="${list.list }" var="user">
															<tr>
																<td class="client-avatar"></td>
																<td><a data-toggle="tab" class="client-link">${user.user_username }</a></td>
																<td>${user.user_name }</td>
																<c:if test="${user.user_power == 1 }">
																	<td>管理员</td>
																</c:if>
																<c:if test="${user.user_power == 2 }">
																	<td>普通用户</td>
																</c:if>
																<c:if test="${user.user_status == 1 }">
																	<td>正常</td>
																</c:if>
																<c:if test="${user.user_status == 2 }">
																	<td>禁用</td>
																</c:if>
																<td class="contact-type"></td>
																<td><fmt:formatDate pattern="yyyy-MM-dd HH:dd:ss" value="${user.create_time }" /></td>
																<td class="client-status">
																	<div class="btn-group">
																		<c:if test="${user.user_status == 1 }">
																			<button class="btn-white btn btn-xs" onclick="changeState('${user.user_username }','${user.user_status }')">禁用</button>
																		</c:if>
																		<c:if test="${user.user_status == 2 }">
																			<button class="btn-white btn btn-xs" onclick="changeState('${user.user_username }','${user.user_status }')">启用</button>
																		</c:if>
											                            <button class="btn-white btn btn-xs" onclick="del('${user.user_username }')">删除</button>
											                            <button class="btn-white btn btn-xs" onclick="changePassword('${user.user_username }')">密码重置</button>
											                        </div>
																</td>
															</tr>
														</c:forEach>
													</tbody>
													<tfoot>
					                                <tr>
					                                    <td colspan="8">
					                                        <c:if test="${list.pages>0}">
																<div class="box" id="box" style="float: right;"></div>
															</c:if>
					                                    </td>
					                                </tr>
					                                </tfoot>
												</table>
											</div>
										<!-- </div> -->
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<jsp:include page="footer.jsp" flush="true" />
	</div>
</div>
</body>
	<!-- Mainly scripts -->
	<script src="${pageContext.request.contextPath }/js/jquery-2.1.1.js"></script>
	<script src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
	<script src="${pageContext.request.contextPath }/js/plugins/metisMenu/jquery.metisMenu.js"></script>
	<script
		src="${pageContext.request.contextPath }/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
	<script src="${pageContext.request.contextPath }/js/mypage.js"></script>
	<!-- Custom and plugin javascript -->
	<script src="${pageContext.request.contextPath }/js/inspinia.js"></script>
	<script
		src="${pageContext.request.contextPath }/js/plugins/pace/pace.min.js"></script>
	<!-- Toastr script -->
    <script src="${pageContext.request.contextPath }/js/plugins/toastr/toastr.min.js"></script>
<script type="text/javascript">
	$(function(){
		paging(1,'${list.pages }','${list.pageNum }');
	});
	

	function paging(totalData,totalPage, pagenum) {
		$('#box').paging({
			initPageNo : pagenum, // 初始页码
			totalPages : totalPage, //总页数
			totalCount : '合计' + totalData + '条数据', // 条目总数
			slideSpeed : 600, // 缓动速度 单位毫秒
			jump : true, //是否支持跳转
			callback : function(page) {
				// 回调函数
			}
		});
	}
	
	function JumpToPage(pagenum){
		window.location.href = "${pageContext.request.contextPath}/userList?pageNum=" +pagenum;
	}
	
	/* 修改状态 */
	function changeState(username,status){
		var data= {username:username,status:status};
		var pagenum = $('.sel-page').text();
		$.ajax({
	        type:"POST",
	        url:"${pageContext.request.contextPath}/modifyState",
	        data:data,
			dataType:'json',
			success:function(result){
		  		if(result !=  0){
		  			if(status == 1){
		  				toastr.success('该用户已经禁用！');
		  				setTimeout(function () {
		  					window.location.href = "${pageContext.request.contextPath}/userList?pageNum=" +pagenum;
	    				}, 800);
		  			}else if(status == 2){
		  				toastr.success('该用户已经启用！');
		  				setTimeout(function () {
		  					window.location.href = "${pageContext.request.contextPath}/userList?pageNum=" +pagenum;
	    				}, 800);
		  			}
				 }else{
					 toastr.error('修改失败！');
				}
			},
		});
		
	}
	
	
	function del(username){
		if (confirm("确认删除?")){
			var data= {username:username};
			var pagenum = $('.sel-page').text();
			$.ajax({
		        type:"POST",
		        url:"${pageContext.request.contextPath}/delStonedtUser",
		        data:data,
				dataType:'json',
				success:function(result){
			  		if(result !=  0){
			  			toastr.success('该用户已删除！');
		  				setTimeout(function () {
		  					window.location.href = "${pageContext.request.contextPath}/userList?pageNum=" +pagenum;
	    				}, 800);
					 }else{
						 toastr.error('删除失败！');
					}
				},
			});
			
		}else{
			return;
		}
	}
	
	
	function changePassword(username){
		if (confirm("密码将会重置为“123456”")){
			var data= {username:username};
			var pagenum = $('.sel-page').text();
			$.ajax({
		        type:"POST",
		        url:"${pageContext.request.contextPath}/resetPwd",
		        data:data,
				dataType:'json',
				success:function(result){
			  		if(result !=  0){
			  			toastr.success('该用户密码已重置为：123456！');
		  				setTimeout(function () {
		  					window.location.href = "${pageContext.request.contextPath}/userList?pageNum=" +pagenum;
	    				}, 800);
					 }else{
						 toastr.error('重置失败！');
					}
				},
			});
			
		}else{
			return;
		}
	}
	
	//跑马灯方法 
// 	 function init(){
// 		    //获取标题
// 		    var title=document.title;
// 		    //分割字符串--->字符数组
// 		    var arr=title.split("");
// 		    //删除第一个元素并返回该元素
// 		    var e=arr.shift();
// 		    //把一个对象添加到数组末尾
// 		    arr.push(e);
// 		    //把数组转换成字符串
// 		    var marquee=arr.join("");
// 		    //返回给浏览器
// 		    document.title=marquee;
// 		    //定时一直执行
// 		    window.setTimeout("init()",1000);
// 		}
// 		window.onload=init;
	 
</script>
</html>